<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>class Numeric - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="class">
  <!-- this is class.html -->

  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->

  <div class='wrapper hdiv'>

    


    <nav id='vapp' role="navigation">
    <div id="project-navigation">
      <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

      <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

    </div>


    
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#class-Numeric-label-What-27s+Here">What’s Here</a>
    <li><a href="#class-Numeric-label-Querying">Querying</a>
    <li><a href="#class-Numeric-label-Comparing">Comparing</a>
    <li><a href="#class-Numeric-label-Converting">Converting</a>
    <li><a href="#class-Numeric-label-Other">Other</a>
  </ul>
</div>


    <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>
    <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
      <div id="class-metadata">
        
        
<div id="parent-class-section" class="nav-section">
  <h3>Parent</h3>

  <p class="link"><a href="Object.html">Object</a>
</div>

        
<div id="includes-section" class="nav-section">
  <h3>Included Modules</h3>

  <ul class="link-list">
    <li><a class="include" href="Comparable.html">Comparable</a>
  </ul>
</div>

        
        
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
  <h3>Methods</h3>

  <ul class="link-list" role="directory">
    <li ><a href="#method-i-25">#%</a>
    <li ><a href="#method-i-2B-40">#+@</a>
    <li ><a href="#method-i-2D-40">#-@</a>
    <li ><a href="#method-i-3C-3D-3E">#&lt;=&gt;</a>
    <li ><a href="#method-i-abs">#abs</a>
    <li ><a href="#method-i-abs2">#abs2</a>
    <li ><a href="#method-i-angle">#angle</a>
    <li ><a href="#method-i-arg">#arg</a>
    <li ><a href="#method-i-ceil">#ceil</a>
    <li ><a href="#method-i-clone">#clone</a>
    <li ><a href="#method-i-coerce">#coerce</a>
    <li ><a href="#method-i-conj">#conj</a>
    <li ><a href="#method-i-conjugate">#conjugate</a>
    <li ><a href="#method-i-denominator">#denominator</a>
    <li ><a href="#method-i-div">#div</a>
    <li ><a href="#method-i-divmod">#divmod</a>
    <li ><a href="#method-i-dup">#dup</a>
    <li ><a href="#method-i-eql-3F">#eql?</a>
    <li ><a href="#method-i-fdiv">#fdiv</a>
    <li ><a href="#method-i-finite-3F">#finite?</a>
    <li ><a href="#method-i-floor">#floor</a>
    <li ><a href="#method-i-i">#i</a>
    <li ><a href="#method-i-imag">#imag</a>
    <li ><a href="#method-i-imaginary">#imaginary</a>
    <li ><a href="#method-i-infinite-3F">#infinite?</a>
    <li ><a href="#method-i-integer-3F">#integer?</a>
    <li ><a href="#method-i-magnitude">#magnitude</a>
    <li ><a href="#method-i-modulo">#modulo</a>
    <li ><a href="#method-i-negative-3F">#negative?</a>
    <li ><a href="#method-i-nonzero-3F">#nonzero?</a>
    <li ><a href="#method-i-numerator">#numerator</a>
    <li ><a href="#method-i-phase">#phase</a>
    <li ><a href="#method-i-polar">#polar</a>
    <li ><a href="#method-i-positive-3F">#positive?</a>
    <li ><a href="#method-i-quo">#quo</a>
    <li ><a href="#method-i-real">#real</a>
    <li ><a href="#method-i-real-3F">#real?</a>
    <li ><a href="#method-i-rect">#rect</a>
    <li ><a href="#method-i-rectangular">#rectangular</a>
    <li ><a href="#method-i-remainder">#remainder</a>
    <li ><a href="#method-i-round">#round</a>
    <li ><a href="#method-i-step">#step</a>
    <li ><a href="#method-i-to_c">#to_c</a>
    <li ><a href="#method-i-to_int">#to_int</a>
    <li ><a href="#method-i-truncate">#truncate</a>
    <li ><a href="#method-i-zero-3F">#zero?</a>
  </ul>
</div>

      </div>
     </div>
    </nav>


    <div id='extraz'><div class='adzbox-index'  >
      
     </div>         
    </div>

    <main role="main" aria-labelledby="class-Numeric">
    <h1 id="class-Numeric" class="class">
      class Numeric
    </h1>

    <section class="description">
    
<p>Numeric is the class from which all higher-level numeric classes should inherit.</p>

<p>Numeric allows instantiation of heap-allocated objects. Other core numeric classes such as <a href="Integer.html"><code>Integer</code></a> are implemented as immediates, which means that each <a href="Integer.html"><code>Integer</code></a> is a single immutable object which is always passed by value.</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-value">1</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">a</span>.<span class="ruby-identifier">object_id</span>   <span class="ruby-comment">#=&gt; true</span>
</pre>

<p>There can only ever be one instance of the integer <code>1</code>, for example. Ruby ensures this by preventing instantiation. If duplication is attempted, the same instance is returned.</p>

<pre class="ruby"><span class="ruby-constant">Integer</span>.<span class="ruby-identifier">new</span>(<span class="ruby-value">1</span>)                   <span class="ruby-comment">#=&gt; NoMethodError: undefined method `new&#39; for Integer:Class</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">dup</span>                            <span class="ruby-comment">#=&gt; 1</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">object_id</span> <span class="ruby-operator">==</span> <span class="ruby-value">1</span>.<span class="ruby-identifier">dup</span>.<span class="ruby-identifier">object_id</span>   <span class="ruby-comment">#=&gt; true</span>
</pre>

<p>For this reason, Numeric should be used when defining other numeric classes.</p>

<p>Classes which inherit from Numeric must implement <code>coerce</code>, which returns a two-member <a href="Array.html"><code>Array</code></a> containing an object that has been coerced into an instance of the new class and <code>self</code> (see <a href="Numeric.html#method-i-coerce"><code>coerce</code></a>).</p>

<p>Inheriting classes should also implement arithmetic operator methods (<code>+</code>, <code>-</code>, <code>*</code> and <code>/</code>) and the <code>&lt;=&gt;</code> operator (see <a href="Comparable.html"><code>Comparable</code></a>). These methods may rely on <code>coerce</code> to ensure interoperability with instances of other numeric classes.</p>

<pre class="ruby"><span class="ruby-keyword">class</span> <span class="ruby-constant">Tally</span> <span class="ruby-operator">&lt;</span> <span class="ruby-constant">Numeric</span>
  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">initialize</span>(<span class="ruby-identifier">string</span>)
    <span class="ruby-ivar">@string</span> = <span class="ruby-identifier">string</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_s</span>
    <span class="ruby-ivar">@string</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">to_i</span>
    <span class="ruby-ivar">@string</span>.<span class="ruby-identifier">size</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">coerce</span>(<span class="ruby-identifier">other</span>)
    [<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;|&#39;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>), <span class="ruby-keyword">self</span>]
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">&lt;=&gt;</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-identifier">to_i</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">+</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;|&#39;</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">to_i</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>))
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">-</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;|&#39;</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">to_i</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>))
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">*</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;|&#39;</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">to_i</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>))
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">/</span>(<span class="ruby-identifier">other</span>)
    <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;|&#39;</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">to_i</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">other</span>.<span class="ruby-identifier">to_i</span>))
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>

<span class="ruby-identifier">tally</span> = <span class="ruby-constant">Tally</span>.<span class="ruby-identifier">new</span>(<span class="ruby-string">&#39;||&#39;</span>)
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">tally</span> <span class="ruby-operator">*</span> <span class="ruby-value">2</span>            <span class="ruby-comment">#=&gt; &quot;||||&quot;</span>
<span class="ruby-identifier">puts</span> <span class="ruby-identifier">tally</span> <span class="ruby-operator">&gt;</span> <span class="ruby-value">1</span>            <span class="ruby-comment">#=&gt; true</span>
</pre>

<h2 id="class-Numeric-label-What-27s+Here">What’s Here<span><a href="#class-Numeric-label-What-27s+Here">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>First, what’s elsewhere. Class Numeric:</p>
<ul><li>
<p>Inherits from <a href="Object.html#class-Object-label-What-27s+Here">class Object</a>.</p>
</li><li>
<p>Includes <a href="Comparable.html#module-Comparable-label-What-27s+Here">module Comparable</a>.</p>
</li></ul>

<p>Here, class Numeric provides methods for:</p>
<ul><li>
<p><a href="Numeric.html#class-Numeric-label-Querying">Querying</a></p>
</li><li>
<p><a href="Numeric.html#class-Numeric-label-Comparing">Comparing</a></p>
</li><li>
<p><a href="Numeric.html#class-Numeric-label-Converting">Converting</a></p>
</li><li>
<p><a href="Numeric.html#class-Numeric-label-Other">Other</a></p>
</li></ul>

<h3 id="class-Numeric-label-Querying">Querying<span><a href="#class-Numeric-label-Querying">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Numeric.html#method-i-finite-3F"><code>finite?</code></a>: Returns true unless <code>self</code> is infinite or not a number.</p>
</li><li>
<p><a href="Numeric.html#method-i-infinite-3F"><code>infinite?</code></a>: Returns -1, <code>nil</code> or +1, depending on whether <code>self</code> is <code>-Infinity&lt;tt&gt;, finite, or &lt;tt&gt;+Infinity</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-integer-3F"><code>integer?</code></a>: Returns whether <code>self</code> is an integer.</p>
</li><li>
<p><a href="Numeric.html#method-i-negative-3F"><code>negative?</code></a>: Returns whether <code>self</code> is negative.</p>
</li><li>
<p><a href="Numeric.html#method-i-nonzero-3F"><code>nonzero?</code></a>: Returns whether <code>self</code> is not zero.</p>
</li><li>
<p><a href="Numeric.html#method-i-positive-3F"><code>positive?</code></a>: Returns whether <code>self</code> is positive.</p>
</li><li>
<p><a href="Numeric.html#method-i-real-3F"><code>real?</code></a>: Returns whether <code>self</code> is a real value.</p>
</li><li>
<p><a href="Numeric.html#method-i-zero-3F"><code>zero?</code></a>: Returns whether <code>self</code> is zero.</p>
</li></ul>

<h3 id="class-Numeric-label-Comparing">Comparing<span><a href="#class-Numeric-label-Comparing">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p>#&lt;=&gt;: Returns:</p>
<ul><li>
<p>-1 if  <code>self</code> is less than the given value.</p>
</li><li>
<p>0 if <code>self</code> is equal to the given value.</p>
</li><li>
<p>1 if <code>self</code> is greater than the given value.</p>
</li><li>
<p><code>nil</code> if <code>self</code> and the given value are not comparable.</p>
</li></ul>
</li><li>
<p><a href="Numeric.html#method-i-eql-3F"><code>eql?</code></a>: Returns whether <code>self</code> and the given value have the same value and type.</p>
</li></ul>

<h3 id="class-Numeric-label-Converting">Converting<span><a href="#class-Numeric-label-Converting">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Numeric.html#method-i-25"><code>%</code></a> (aliased as <a href="Numeric.html#method-i-modulo"><code>modulo</code></a>): Returns the remainder of <code>self</code> divided by the given value.</p>
</li><li>
<p><a href="Numeric.html#method-i-2D-40"><code>-@</code></a>: Returns the value of <code>self</code>, negated.</p>
</li><li>
<p><a href="Numeric.html#method-i-abs"><code>abs</code></a> (aliased as <a href="Numeric.html#method-i-magnitude"><code>magnitude</code></a>): Returns the absolute value of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-abs2"><code>abs2</code></a>: Returns the square of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-angle"><code>angle</code></a> (aliased as <a href="Numeric.html#method-i-arg"><code>arg</code></a> and <a href="Numeric.html#method-i-phase"><code>phase</code></a>): Returns 0 if <code>self</code> is positive, Math::PI otherwise.</p>
</li><li>
<p><a href="Numeric.html#method-i-ceil"><code>ceil</code></a>: Returns the smallest number greater than or equal to <code>self</code>, to a given precision.</p>
</li><li>
<p><a href="Numeric.html#method-i-coerce"><code>coerce</code></a>: Returns array <code>[coerced_self, coerced_other]</code> for the given other value.</p>
</li><li>
<p><a href="Numeric.html#method-i-conj"><code>conj</code></a> (aliased as <a href="Numeric.html#method-i-conjugate"><code>conjugate</code></a>): Returns the complex conjugate of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-denominator"><code>denominator</code></a>: Returns the denominator (always positive) of the <a href="Rational.html"><code>Rational</code></a> representation of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-div"><code>div</code></a>: Returns the value of <code>self</code> divided by the given value and converted to an integer.</p>
</li><li>
<p><a href="Numeric.html#method-i-divmod"><code>divmod</code></a>: Returns array <code>[quotient, modulus]</code> resulting from dividing <code>self</code> the given divisor.</p>
</li><li>
<p><a href="Numeric.html#method-i-fdiv"><code>fdiv</code></a>: Returns the <a href="Float.html"><code>Float</code></a> result of dividing <code>self</code> by the given divisor.</p>
</li><li>
<p><a href="Numeric.html#method-i-floor"><code>floor</code></a>: Returns the largest number less than or equal to <code>self</code>, to a given precision.</p>
</li><li>
<p><a href="Numeric.html#method-i-i"><code>i</code></a>: Returns the <a href="Complex.html"><code>Complex</code></a> object <code>Complex(0, self)</code>. the given value.</p>
</li><li>
<p><a href="Numeric.html#method-i-imaginary"><code>imaginary</code></a> (aliased as <a href="Numeric.html#method-i-imag"><code>imag</code></a>): Returns the imaginary part of the <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-numerator"><code>numerator</code></a>: Returns the numerator of the <a href="Rational.html"><code>Rational</code></a> representation of <code>self</code>; has the same sign as <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-polar"><code>polar</code></a>: Returns the array <code>[self.abs, self.arg]</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-quo"><code>quo</code></a>: Returns the value of <code>self</code> divided by the given value.</p>
</li><li>
<p><a href="Numeric.html#method-i-real"><code>real</code></a>: Returns the real part of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-rect"><code>rect</code></a> (aliased as <a href="Numeric.html#method-i-rectangular"><code>rectangular</code></a>): Returns the array <code>[self, 0]</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-remainder"><code>remainder</code></a>: Returns <code>self-arg*(self/arg).truncate</code> for the given <code>arg</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-round"><code>round</code></a>: Returns the value of <code>self</code> rounded to the nearest value for the given a precision.</p>
</li><li>
<p><a href="Numeric.html#method-i-to_c"><code>to_c</code></a>: Returns the <a href="Complex.html"><code>Complex</code></a> representation of <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-to_int"><code>to_int</code></a>: Returns the <a href="Integer.html"><code>Integer</code></a> representation of <code>self</code>, truncating if necessary.</p>
</li><li>
<p><a href="Numeric.html#method-i-truncate"><code>truncate</code></a>: Returns <code>self</code> truncated (toward zero) to a given precision.</p>
</li></ul>

<h3 id="class-Numeric-label-Other">Other<span><a href="#class-Numeric-label-Other">&para;</a> <a href="#top">&uarr;</a></span></h3>
<ul><li>
<p><a href="Numeric.html#method-i-clone"><code>clone</code></a>: Returns <code>self</code>; does not allow freezing.</p>
</li><li>
<p><a href="Numeric.html#method-i-dup"><code>dup</code></a> (aliased as <a href="Numeric.html#method-i-2B-40"><code>+@</code></a>): Returns <code>self</code>.</p>
</li><li>
<p><a href="Numeric.html#method-i-step"><code>step</code></a>: Invokes the given block with the sequence of specified numbers.</p>
</li></ul>

    </section>

      <section id="5Buntitled-5D" class="documentation-section">





                <section id="public-instance-5Buntitled-5D-method-details" class="method-section">
                <header>
                <h3>Public Instance Methods</h3>
                </header>

                  <div id="method-i-25" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          self % other &rarr; real_numeric
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> modulo <code>other</code> as a real number.</p>

<p>Of the Core and Standard Library classes, only <a href="Rational.html"><code>Rational</code></a> uses this implementation.</p>

<p>For <a href="Rational.html"><code>Rational</code></a> <code>r</code> and real number <code>n</code>, these expressions are equivalent:</p>

<pre class="ruby"><span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">n</span>
<span class="ruby-identifier">r</span><span class="ruby-operator">-</span><span class="ruby-identifier">n</span><span class="ruby-operator">*</span>(<span class="ruby-identifier">r</span><span class="ruby-operator">/</span><span class="ruby-identifier">n</span>).<span class="ruby-identifier">floor</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">divmod</span>(<span class="ruby-identifier">n</span>)[<span class="ruby-value">1</span>]
</pre>

<p>See <a href="Numeric.html#method-i-divmod"><code>Numeric#divmod</code></a>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">r</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)    <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r2</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment"># =&gt; (2/3)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>                <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-value">2</span>                 <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-value">2.0</span>               <span class="ruby-comment"># =&gt; 0.5</span>

<span class="ruby-identifier">r</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">301</span>,<span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; (301/100)</span>
<span class="ruby-identifier">r2</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">7</span>,<span class="ruby-value">5</span>)    <span class="ruby-comment"># =&gt; (7/5)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>                <span class="ruby-comment"># =&gt; (21/100)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-operator">-</span><span class="ruby-identifier">r2</span>               <span class="ruby-comment"># =&gt; (-119/100)</span>
(<span class="ruby-operator">-</span><span class="ruby-identifier">r</span>) <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>             <span class="ruby-comment"># =&gt; (119/100)</span>
(<span class="ruby-operator">-</span><span class="ruby-identifier">r</span>) <span class="ruby-operator">%</span><span class="ruby-operator">-</span><span class="ruby-identifier">r2</span>             <span class="ruby-comment"># =&gt; (-21/100)</span>
</pre>

                              <div class="method-source-code" id="25-source">
            <pre>static VALUE
num_modulo(VALUE x, VALUE y)
{
    VALUE q = num_funcall1(x, id_div, y);
    return rb_funcall(x, &#39;-&#39;, 1,
                      rb_funcall(y, &#39;*&#39;, 1, q));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-modulo">modulo</a>
                            </div>

                          </div>

                  <div id="method-i-2B-40" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          +self &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code>.</p>

                              <div class="method-source-code" id="2B-40-source">
            <pre>static VALUE
num_uplus(VALUE num)
{
    return num;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-2D-40" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          -self &rarr; numeric
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Unary Minus—Returns the receiver, negated.</p>

                              <div class="method-source-code" id="2D-40-source">
            <pre>static VALUE
num_uminus(VALUE num)
{
    VALUE zero;

    zero = INT2FIX(0);
    do_coerce(&amp;zero, &amp;num, TRUE);

    return num_funcall1(zero, &#39;-&#39;, num);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-3C-3D-3E" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          self &lt;=&gt; other &rarr; zero or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns zero if <code>self</code> is the same as <code>other</code>, <code>nil</code> otherwise.</p>

<p>No subclass in the Ruby Core or Standard Library uses this implementation.</p>

                              <div class="method-source-code" id="3C-3D-3E-source">
            <pre>static VALUE
num_cmp(VALUE x, VALUE y)
{
    if (x == y) return INT2FIX(0);
    return Qnil;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-abs" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          abs &rarr; numeric
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute value of <code>self</code>.</p>

<pre class="ruby"><span class="ruby-value">12</span>.<span class="ruby-identifier">abs</span>        <span class="ruby-comment">#=&gt; 12</span>
(<span class="ruby-value">-34.56</span>).<span class="ruby-identifier">abs</span>  <span class="ruby-comment">#=&gt; 34.56</span>
<span class="ruby-value">-34.56</span>.<span class="ruby-identifier">abs</span>    <span class="ruby-comment">#=&gt; 34.56</span>
</pre>

                              <div class="method-source-code" id="abs-source">
            <pre>static VALUE
num_abs(VALUE num)
{
    if (rb_num_negative_int_p(num)) {
        return num_funcall0(num, idUMinus);
    }
    return num;
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-magnitude">magnitude</a>
                            </div>

                          </div>

                  <div id="method-i-abs2" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          abs2  &rarr;  real
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns square of self.</p>

                              <div class="method-source-code" id="abs2-source">
            <pre>static VALUE
numeric_abs2(VALUE self)
{
    return f_mul(self, self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-angle" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          angle  &rarr;  0 or float
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns 0 if the value is positive, pi otherwise.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-arg">arg</a>
                            </div>
                          </div>

                  <div id="method-i-arg" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          arg    &rarr;  0 or float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns 0 if the value is positive, pi otherwise.</p>

                              <div class="method-source-code" id="arg-source">
            <pre>static VALUE
numeric_arg(VALUE self)
{
    if (f_positive_p(self))
        return INT2FIX(0);
    return DBL2NUM(M_PI);
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-angle">angle</a>, <a href="Numeric.html#method-i-phase">phase</a>
                            </div>

                          </div>

                  <div id="method-i-ceil" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          ceil(digits = 0) &rarr; integer or float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the smallest number that is greater than or equal to <code>self</code> with a precision of <code>digits</code> decimal digits.</p>

<p>Numeric implements this by converting <code>self</code> to a <a href="Float.html"><code>Float</code></a> and invoking <a href="Float.html#method-i-ceil"><code>Float#ceil</code></a>.</p>

                              <div class="method-source-code" id="ceil-source">
            <pre>static VALUE
num_ceil(int argc, VALUE *argv, VALUE num)
{
    return flo_ceil(argc, argv, rb_Float(num));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-clone" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          clone(freeze: true) &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code>.</p>

<p>Raises an exception if the value for <code>freeze</code> is neither <code>true</code> nor <code>nil</code>.</p>

<p>Related: <a href="Numeric.html#method-i-dup"><code>Numeric#dup</code></a>.</p>

                              <div class="method-source-code" id="clone-source">
            <pre>static VALUE
num_clone(int argc, VALUE *argv, VALUE x)
{
    return rb_immutable_obj_clone(argc, argv, x);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-coerce" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          coerce(other) &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a 2-element array containing two numeric elements, formed from the two operands <code>self</code> and <code>other</code>, of a common compatible type.</p>

<p>Of the Core and Standard Library classes, <a href="Integer.html"><code>Integer</code></a>, <a href="Rational.html"><code>Rational</code></a>, and <a href="Complex.html"><code>Complex</code></a> use this implementation.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">i</span> = <span class="ruby-value">2</span>                    <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-identifier">i</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">3</span>)              <span class="ruby-comment"># =&gt; [3, 2]</span>
<span class="ruby-identifier">i</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">3.0</span>)            <span class="ruby-comment"># =&gt; [3.0, 2.0]</span>
<span class="ruby-identifier">i</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)) <span class="ruby-comment"># =&gt; [0.5, 2.0]</span>
<span class="ruby-identifier">i</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-value">3</span>, <span class="ruby-value">4</span>))  <span class="ruby-comment"># Raises RangeError.</span>

<span class="ruby-identifier">r</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">5</span>, <span class="ruby-value">2</span>)       <span class="ruby-comment"># =&gt; (5/2)</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">2</span>)              <span class="ruby-comment"># =&gt; [(2/1), (5/2)]</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">2.0</span>)            <span class="ruby-comment"># =&gt; [2.0, 2.5]</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)) <span class="ruby-comment"># =&gt; [(2/3), (5/2)]</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-value">3</span>, <span class="ruby-value">4</span>))  <span class="ruby-comment"># =&gt; [(3+4i), ((5/2)+0i)]</span>

<span class="ruby-identifier">c</span> = <span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)        <span class="ruby-comment"># =&gt; (2+3i)</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">2</span>)              <span class="ruby-comment"># =&gt; [(2+0i), (2+3i)]</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-value">2.0</span>)            <span class="ruby-comment"># =&gt; [(2.0+0i), (2+3i)]</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)) <span class="ruby-comment"># =&gt; [((1/2)+0i), (2+3i)]</span>
<span class="ruby-identifier">c</span>.<span class="ruby-identifier">coerce</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-value">3</span>, <span class="ruby-value">4</span>))  <span class="ruby-comment"># =&gt; [(3+4i), (2+3i)]</span>
</pre>

<p>Raises an exception if any type conversion fails.</p>

                              <div class="method-source-code" id="coerce-source">
            <pre>static VALUE
num_coerce(VALUE x, VALUE y)
{
    if (CLASS_OF(x) == CLASS_OF(y))
        return rb_assoc_new(y, x);
    x = rb_Float(x);
    y = rb_Float(y);
    return rb_assoc_new(y, x);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-conj" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          conj &rarr; self
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-conjugate">conjugate</a>
                            </div>
                          </div>

                  <div id="method-i-conjugate" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">conjugate</span><span
                                class="method-args"> -&gt; self</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code>.</p>

                              <div class="method-source-code" id="conjugate-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 68</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">conjugate</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-conj">conj</a>
                            </div>

                          </div>

                  <div id="method-i-denominator" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          denominator  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the denominator (always positive).</p>

                              <div class="method-source-code" id="denominator-source">
            <pre>static VALUE
numeric_denominator(VALUE self)
{
    return f_denominator(f_to_r(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-div" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          div(other) &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the quotient <code>self/other</code> as an integer (via <code>floor</code>), using method <code>/</code> in the derived class of <code>self</code>. (Numeric itself does not define method <code>/</code>.)</p>

<p>Of the Core and Standard Library classes, Only <a href="Float.html"><code>Float</code></a> and <a href="Rational.html"><code>Rational</code></a> use this implementation.</p>

                              <div class="method-source-code" id="div-source">
            <pre>static VALUE
num_div(VALUE x, VALUE y)
{
    if (rb_equal(INT2FIX(0), y)) rb_num_zerodiv();
    return rb_funcall(num_funcall1(x, &#39;/&#39;, y), rb_intern(&quot;floor&quot;), 0);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-divmod" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          divmod(other) &rarr; array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns a 2-element array <code>[q, r]</code>, where</p>

<pre class="ruby"><span class="ruby-identifier">q</span> = (<span class="ruby-keyword">self</span><span class="ruby-operator">/</span><span class="ruby-identifier">other</span>).<span class="ruby-identifier">floor</span>                  <span class="ruby-comment"># Quotient</span>
<span class="ruby-identifier">r</span> = <span class="ruby-keyword">self</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">other</span>                        <span class="ruby-comment"># Remainder</span>
</pre>

<p>Of the Core and Standard Library classes, only <a href="Rational.html"><code>Rational</code></a> uses this implementation.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">Rational</span>(<span class="ruby-value">11</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">4</span>)               <span class="ruby-comment"># =&gt; [2, (3/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">11</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">-4</span>)              <span class="ruby-comment"># =&gt; [-3, (-1/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-11</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">4</span>)              <span class="ruby-comment"># =&gt; [-3, (1/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-11</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">-4</span>)             <span class="ruby-comment"># =&gt; [2, (-3/1)]</span>

<span class="ruby-constant">Rational</span>(<span class="ruby-value">12</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">4</span>)               <span class="ruby-comment"># =&gt; [3, (0/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">12</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">-4</span>)              <span class="ruby-comment"># =&gt; [-3, (0/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-12</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">4</span>)              <span class="ruby-comment"># =&gt; [-3, (0/1)]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-12</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">-4</span>)             <span class="ruby-comment"># =&gt; [3, (0/1)]</span>

<span class="ruby-constant">Rational</span>(<span class="ruby-value">13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-value">4.0</span>)             <span class="ruby-comment"># =&gt; [3, 1.0]</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">divmod</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">4</span>, <span class="ruby-value">11</span>)) <span class="ruby-comment"># =&gt; [35, (3/11)]</span>
</pre>

                              <div class="method-source-code" id="divmod-source">
            <pre>static VALUE
num_divmod(VALUE x, VALUE y)
{
    return rb_assoc_new(num_div(x, y), num_modulo(x, y));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-dup" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          dup &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code>.</p>

<p>Related: <a href="Numeric.html#method-i-clone"><code>Numeric#clone</code></a>.</p>

                              <div class="method-source-code" id="dup-source">
            <pre>static VALUE
num_dup(VALUE x)
{
    return x;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-eql-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          eql?(other) &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> and <code>other</code> are the same type and have equal values.</p>

<p>Of the Core and Standard Library classes, only <a href="Integer.html"><code>Integer</code></a>, <a href="Rational.html"><code>Rational</code></a>, and <a href="Complex.html"><code>Complex</code></a> use this implementation.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-value">1</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-value">1</span>)              <span class="ruby-comment"># =&gt; true</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-value">1.0</span>)            <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">1</span>)) <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">eql?</span>(<span class="ruby-constant">Complex</span>(<span class="ruby-value">1</span>, <span class="ruby-value">0</span>))  <span class="ruby-comment"># =&gt; false</span>
</pre>

<p>Method <code>eql?</code> is different from +==+ in that <code>eql?</code> requires matching types, while +==+ does not.</p>

                              <div class="method-source-code" id="eql-3F-source">
            <pre>static VALUE
num_eql(VALUE x, VALUE y)
{
    if (TYPE(x) != TYPE(y)) return Qfalse;

    if (RB_BIGNUM_TYPE_P(x)) {
        return rb_big_eql(x, y);
    }

    return rb_equal(x, y);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-fdiv" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          fdiv(other) &rarr; float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the quotient <code>self/other</code> as a float, using method <code>/</code> in the derived class of <code>self</code>. (Numeric itself does not define method <code>/</code>.)</p>

<p>Of the Core and Standard Library classes, only BigDecimal uses this implementation.</p>

                              <div class="method-source-code" id="fdiv-source">
            <pre>static VALUE
num_fdiv(VALUE x, VALUE y)
{
    return rb_funcall(rb_Float(x), &#39;/&#39;, 1, y);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-finite-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          finite? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is a finite number, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="finite-3F-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 38</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">finite?</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-floor" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          floor(digits = 0) &rarr; integer or float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the largest number that is less than or equal to <code>self</code> with a precision of <code>digits</code> decimal digits.</p>

<p>Numeric implements this by converting <code>self</code> to a <a href="Float.html"><code>Float</code></a> and invoking <a href="Float.html#method-i-floor"><code>Float#floor</code></a>.</p>

                              <div class="method-source-code" id="floor-source">
            <pre>static VALUE
num_floor(int argc, VALUE *argv, VALUE num)
{
    return flo_floor(argc, argv, rb_Float(num));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-i" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          i &rarr; complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>Complex(0, self)</code>:</p>

<pre class="ruby"><span class="ruby-value">2</span>.<span class="ruby-identifier">i</span>              <span class="ruby-comment"># =&gt; (0+2i)</span>
<span class="ruby-value">-2</span>.<span class="ruby-identifier">i</span>             <span class="ruby-comment"># =&gt; (0-2i)</span>
<span class="ruby-value">2.0</span>.<span class="ruby-identifier">i</span>            <span class="ruby-comment"># =&gt; (0+2.0i)</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">i</span> <span class="ruby-comment"># =&gt; (0+(1/2)*i)</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">3</span>, <span class="ruby-value">4</span>).<span class="ruby-identifier">i</span>  <span class="ruby-comment"># Raises NoMethodError.</span>
</pre>

                              <div class="method-source-code" id="i-source">
            <pre>static VALUE
num_imaginary(VALUE num)
{
    return rb_complex_new(INT2FIX(0), num);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-imag" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          imag &rarr; 0
                              </span>
                            </div>

                            <div class="method-description">
                              

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-imaginary">imaginary</a>
                            </div>
                          </div>

                  <div id="method-i-imaginary" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">imaginary</span><span
                                class="method-args"> -&gt; 0</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns zero.</p>

                              <div class="method-source-code" id="imaginary-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 57</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">imaginary</span>
  <span class="ruby-value">0</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-imag">imag</a>
                            </div>

                          </div>

                  <div id="method-i-infinite-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          infinite? &rarr; -1, 1, or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>nil</code>, -1, or 1 depending on whether <code>self</code> is finite, <code>-Infinity</code>, or <code>+Infinity</code>.</p>

                              <div class="method-source-code" id="infinite-3F-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 48</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">infinite?</span>
  <span class="ruby-keyword">nil</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-integer-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          integer? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is an <a href="Integer.html"><code>Integer</code></a>.</p>

<pre class="ruby"><span class="ruby-value">1.0</span>.<span class="ruby-identifier">integer?</span> <span class="ruby-comment"># =&gt; false</span>
<span class="ruby-value">1</span>.<span class="ruby-identifier">integer?</span>   <span class="ruby-comment"># =&gt; true</span>
</pre>

                              <div class="method-source-code" id="integer-3F-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 29</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">integer?</span>
  <span class="ruby-keyword">false</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-magnitude" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">magnitude</span><span
                                class="method-args">()</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the absolute value of <code>self</code>.</p>

<pre class="ruby"><span class="ruby-value">12</span>.<span class="ruby-identifier">abs</span>        <span class="ruby-comment">#=&gt; 12</span>
(<span class="ruby-value">-34.56</span>).<span class="ruby-identifier">abs</span>  <span class="ruby-comment">#=&gt; 34.56</span>
<span class="ruby-value">-34.56</span>.<span class="ruby-identifier">abs</span>    <span class="ruby-comment">#=&gt; 34.56</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-abs">abs</a>
                            </div>
                          </div>

                  <div id="method-i-modulo" class="method-detail method-alias">
                            <div class="method-heading">
                              <span class="method-name">modulo</span><span
                                class="method-args">(p1)</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> modulo <code>other</code> as a real number.</p>

<p>Of the Core and Standard Library classes, only <a href="Rational.html"><code>Rational</code></a> uses this implementation.</p>

<p>For <a href="Rational.html"><code>Rational</code></a> <code>r</code> and real number <code>n</code>, these expressions are equivalent:</p>

<pre class="ruby"><span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">n</span>
<span class="ruby-identifier">r</span><span class="ruby-operator">-</span><span class="ruby-identifier">n</span><span class="ruby-operator">*</span>(<span class="ruby-identifier">r</span><span class="ruby-operator">/</span><span class="ruby-identifier">n</span>).<span class="ruby-identifier">floor</span>
<span class="ruby-identifier">r</span>.<span class="ruby-identifier">divmod</span>(<span class="ruby-identifier">n</span>)[<span class="ruby-value">1</span>]
</pre>

<p>See <a href="Numeric.html#method-i-divmod"><code>Numeric#divmod</code></a>.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">r</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>)    <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r2</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">2</span>, <span class="ruby-value">3</span>)   <span class="ruby-comment"># =&gt; (2/3)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>                <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-value">2</span>                 <span class="ruby-comment"># =&gt; (1/2)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-value">2.0</span>               <span class="ruby-comment"># =&gt; 0.5</span>

<span class="ruby-identifier">r</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">301</span>,<span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; (301/100)</span>
<span class="ruby-identifier">r2</span> = <span class="ruby-constant">Rational</span>(<span class="ruby-value">7</span>,<span class="ruby-value">5</span>)    <span class="ruby-comment"># =&gt; (7/5)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>                <span class="ruby-comment"># =&gt; (21/100)</span>
<span class="ruby-identifier">r</span> <span class="ruby-operator">%</span> <span class="ruby-operator">-</span><span class="ruby-identifier">r2</span>               <span class="ruby-comment"># =&gt; (-119/100)</span>
(<span class="ruby-operator">-</span><span class="ruby-identifier">r</span>) <span class="ruby-operator">%</span> <span class="ruby-identifier">r2</span>             <span class="ruby-comment"># =&gt; (119/100)</span>
(<span class="ruby-operator">-</span><span class="ruby-identifier">r</span>) <span class="ruby-operator">%</span><span class="ruby-operator">-</span><span class="ruby-identifier">r2</span>             <span class="ruby-comment"># =&gt; (-21/100)</span>
</pre>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-25">%</a>
                            </div>
                          </div>

                  <div id="method-i-negative-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          negative? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is less than 0, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="negative-3F-source">
            <pre>static VALUE
num_negative_p(VALUE num)
{
    return RBOOL(rb_num_negative_int_p(num));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-nonzero-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          nonzero?  &rarr;  self or nil
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> if <code>self</code> is not a zero value, <code>nil</code> otherwise; uses method <code>zero?</code> for the evaluation.</p>

<p>The returned <code>self</code> allows the method to be chained:</p>

<pre class="ruby"><span class="ruby-identifier">a</span> = <span class="ruby-node">%w[z Bb bB bb BB a aA Aa AA A]</span>
<span class="ruby-identifier">a</span>.<span class="ruby-identifier">sort</span> {<span class="ruby-operator">|</span><span class="ruby-identifier">a</span>, <span class="ruby-identifier">b</span><span class="ruby-operator">|</span> (<span class="ruby-identifier">a</span>.<span class="ruby-identifier">downcase</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">b</span>.<span class="ruby-identifier">downcase</span>).<span class="ruby-identifier">nonzero?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">a</span> <span class="ruby-operator">&lt;=&gt;</span> <span class="ruby-identifier">b</span> }
<span class="ruby-comment"># =&gt; [&quot;A&quot;, &quot;a&quot;, &quot;AA&quot;, &quot;Aa&quot;, &quot;aA&quot;, &quot;BB&quot;, &quot;Bb&quot;, &quot;bB&quot;, &quot;bb&quot;, &quot;z&quot;]</span>
</pre>

<p>Of the Core and Standard Library classes, <a href="Integer.html"><code>Integer</code></a>, <a href="Float.html"><code>Float</code></a>, <a href="Rational.html"><code>Rational</code></a>, and <a href="Complex.html"><code>Complex</code></a> use this implementation.</p>

                              <div class="method-source-code" id="nonzero-3F-source">
            <pre>static VALUE
num_nonzero_p(VALUE num)
{
    if (RTEST(num_funcall0(num, rb_intern(&quot;zero?&quot;)))) {
        return Qnil;
    }
    return num;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-numerator" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          numerator  &rarr;  integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the numerator.</p>

                              <div class="method-source-code" id="numerator-source">
            <pre>static VALUE
numeric_numerator(VALUE self)
{
    return f_numerator(f_to_r(self));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-phase" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          phase  &rarr;  0 or float
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns 0 if the value is positive, pi otherwise.</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-arg">arg</a>
                            </div>
                          </div>

                  <div id="method-i-polar" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          polar  &rarr;  array
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array; [num.abs, num.arg].</p>

                              <div class="method-source-code" id="polar-source">
            <pre>static VALUE
numeric_polar(VALUE self)
{
    VALUE abs, arg;

    if (RB_INTEGER_TYPE_P(self)) {
        abs = rb_int_abs(self);
        arg = numeric_arg(self);
    }
    else if (RB_FLOAT_TYPE_P(self)) {
        abs = rb_float_abs(self);
        arg = float_arg(self);
    }
    else if (RB_TYPE_P(self, T_RATIONAL)) {
        abs = rb_rational_abs(self);
        arg = numeric_arg(self);
    }
    else {
        abs = f_abs(self);
        arg = f_arg(self);
    }
    return rb_assoc_new(abs, arg);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-positive-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          positive? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is greater than 0, <code>false</code> otherwise.</p>

                              <div class="method-source-code" id="positive-3F-source">
            <pre>static VALUE
num_positive_p(VALUE num)
{
    const ID mid = &#39;&gt;&#39;;

    if (FIXNUM_P(num)) {
        if (method_basic_p(rb_cInteger))
            return RBOOL((SIGNED_VALUE)num &gt; (SIGNED_VALUE)INT2FIX(0));
    }
    else if (RB_BIGNUM_TYPE_P(num)) {
        if (method_basic_p(rb_cInteger))
            return RBOOL(BIGNUM_POSITIVE_P(num) &amp;&amp; !rb_bigzero_p(num));
    }
    return rb_num_compare_with_zero(num, mid);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-quo" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          quo(int_or_rat)   &rarr;  rat
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          quo(flo)          &rarr;  flo
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns the most exact division (rational for integers, float for floats).</p>

                              <div class="method-source-code" id="quo-source">
            <pre>VALUE
rb_numeric_quo(VALUE x, VALUE y)
{
    if (RB_TYPE_P(x, T_COMPLEX)) {
        return rb_complex_div(x, y);
    }

    if (RB_FLOAT_TYPE_P(y)) {
        return rb_funcallv(x, idFdiv, 1, &amp;y);
    }

    x = rb_convert_type(x, T_RATIONAL, &quot;Rational&quot;, &quot;to_r&quot;);
    return rb_rational_div(x, y);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          real &rarr; self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code>.</p>

                              <div class="method-source-code" id="real-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">real</span>
  <span class="ruby-keyword">self</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-real-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          real? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>self</code> is a real number (i.e. not <a href="Complex.html"><code>Complex</code></a>).</p>

                              <div class="method-source-code" id="real-3F-source">
            <pre><span class="ruby-comment"># File ruby_3_3_0_preview2/numeric.rb, line 8</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">real?</span>
  <span class="ruby-keyword">true</span>
<span class="ruby-keyword">end</span></pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-rect" class="method-detail method-alias">
                      <div class="method-heading">
                        <span class="method-callseq">
                          rect  &rarr;  array
                              </span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array; [num, 0].</p>

                            </div>


                            <div class="aliases">
                              Alias for: <a href="Numeric.html#method-i-rectangular">rectangular</a>
                            </div>
                          </div>

                  <div id="method-i-rectangular" class="method-detail ">
                            <div class="method-heading">
                              <span class="method-name">rectangular</span><span
                                class="method-args">  -&gt;  array</span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns an array; [num, 0].</p>

                              <div class="method-source-code" id="rectangular-source">
            <pre>static VALUE
numeric_rect(VALUE self)
{
    return rb_assoc_new(self, INT2FIX(0));
}</pre>
                              </div>
                            </div>

                            <div class="aliases">
                              Also aliased as: <a href="Numeric.html#method-i-rect">rect</a>
                            </div>

                          </div>

                  <div id="method-i-remainder" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          remainder(other) &rarr; real_number
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the remainder after dividing <code>self</code> by <code>other</code>.</p>

<p>Of the Core and Standard Library classes, only <a href="Float.html"><code>Float</code></a> and <a href="Rational.html"><code>Rational</code></a> use this implementation.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-value">11.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)              <span class="ruby-comment"># =&gt; 3.0</span>
<span class="ruby-value">11.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>)             <span class="ruby-comment"># =&gt; 3.0</span>
<span class="ruby-value">-11.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)             <span class="ruby-comment"># =&gt; -3.0</span>
<span class="ruby-value">-11.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>)            <span class="ruby-comment"># =&gt; -3.0</span>

<span class="ruby-value">12.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)              <span class="ruby-comment"># =&gt; 0.0</span>
<span class="ruby-value">12.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>)             <span class="ruby-comment"># =&gt; 0.0</span>
<span class="ruby-value">-12.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)             <span class="ruby-comment"># =&gt; -0.0</span>
<span class="ruby-value">-12.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>)            <span class="ruby-comment"># =&gt; -0.0</span>

<span class="ruby-value">13.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4.0</span>)            <span class="ruby-comment"># =&gt; 1.0</span>
<span class="ruby-value">13.0</span>.<span class="ruby-identifier">remainder</span>(<span class="ruby-constant">Rational</span>(<span class="ruby-value">4</span>, <span class="ruby-value">1</span>)) <span class="ruby-comment"># =&gt; 1.0</span>

<span class="ruby-constant">Rational</span>(<span class="ruby-value">13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)   <span class="ruby-comment"># =&gt; (1/1)</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>)  <span class="ruby-comment"># =&gt; (1/1)</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">remainder</span>(<span class="ruby-value">4</span>)  <span class="ruby-comment"># =&gt; (-1/1)</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">-13</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">remainder</span>(<span class="ruby-value">-4</span>) <span class="ruby-comment"># =&gt; (-1/1)</span>
</pre>

                              <div class="method-source-code" id="remainder-source">
            <pre>static VALUE
num_remainder(VALUE x, VALUE y)
{
    if (!rb_obj_is_kind_of(y, rb_cNumeric)) {
        do_coerce(&amp;x, &amp;y, TRUE);
    }
    VALUE z = num_funcall1(x, &#39;%&#39;, y);

    if ((!rb_equal(z, INT2FIX(0))) &amp;&amp;
        ((rb_num_negative_int_p(x) &amp;&amp;
          rb_num_positive_int_p(y)) ||
         (rb_num_positive_int_p(x) &amp;&amp;
          rb_num_negative_int_p(y)))) {
        if (RB_FLOAT_TYPE_P(y)) {
            if (isinf(RFLOAT_VALUE(y))) {
                return x;
            }
        }
        return rb_funcall(z, &#39;-&#39;, 1, y);
    }
    return z;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-round" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          round(digits = 0) &rarr; integer or float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> rounded to the nearest value with a precision of <code>digits</code> decimal digits.</p>

<p>Numeric implements this by converting <code>self</code> to a <a href="Float.html"><code>Float</code></a> and invoking <a href="Float.html#method-i-round"><code>Float#round</code></a>.</p>

                              <div class="method-source-code" id="round-source">
            <pre>static VALUE
num_round(int argc, VALUE* argv, VALUE num)
{
    return flo_round(argc, argv, rb_Float(num));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-step" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(to = nil, by = 1) {|n| ... } &rarr;  self
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(to = nil, by = 1)            &rarr;  enumerator
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(to = nil, by: 1) {|n| ... }  &rarr;  self
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(to = nil, by: 1)             &rarr;  enumerator
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(by: 1, to: ) {|n| ... }      &rarr;  self
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(by: 1, to: )                 &rarr;  enumerator
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(by: , to: nil) {|n| ... }    &rarr;  self
                              </span>
                            </div>
                      <div class="method-heading">
                        <span class="method-callseq">
                          step(by: , to: nil)               &rarr;  enumerator
                              </span>
                            </div>

                            <div class="method-description">
                              <pre>Generates a sequence of numbers; with a block given, traverses the sequence.

Of the Core and Standard Library classes,
Integer, Float, and Rational use this implementation.

A quick example:

  squares = []
  1.step(by: 2, to: 10) {|i| squares.push(i*i) }
  squares # =&gt; [1, 9, 25, 49, 81]

The generated sequence:

- Begins with +self+.
- Continues at intervals of +step+ (which may not be zero).
- Ends with the last number that is within or equal to +limit+;
  that is, less than or equal to +limit+ if +step+ is positive,
  greater than or equal to +limit+ if +step+ is negative.
  If +limit+ is not given, the sequence is of infinite length.

If a block is given, calls the block with each number in the sequence;
returns +self+.  If no block is given, returns an Enumerator::ArithmeticSequence.

&lt;b&gt;Keyword Arguments&lt;/b&gt;

With keyword arguments +by+ and +to+,
their values (or defaults) determine the step and limit:

  # Both keywords given.
  squares = []
  4.step(by: 2, to: 10) {|i| squares.push(i*i) }    # =&gt; 4
  squares # =&gt; [16, 36, 64, 100]
  cubes = []
  3.step(by: -1.5, to: -3) {|i| cubes.push(i*i*i) } # =&gt; 3
  cubes   # =&gt; [27.0, 3.375, 0.0, -3.375, -27.0]
  squares = []
  1.2.step(by: 0.2, to: 2.0) {|f| squares.push(f*f) }
  squares # =&gt; [1.44, 1.9599999999999997, 2.5600000000000005, 3.24, 4.0]

  squares = []
  Rational(6/5).step(by: 0.2, to: 2.0) {|r| squares.push(r*r) }
  squares # =&gt; [1.0, 1.44, 1.9599999999999997, 2.5600000000000005, 3.24, 4.0]

  # Only keyword to given.
  squares = []
  4.step(to: 10) {|i| squares.push(i*i) }           # =&gt; 4
  squares # =&gt; [16, 25, 36, 49, 64, 81, 100]
  # Only by given.

  # Only keyword by given
  squares = []
  4.step(by:2) {|i| squares.push(i*i); break if i &gt; 10 }
  squares # =&gt; [16, 36, 64, 100, 144]

  # No block given.
  e = 3.step(by: -1.5, to: -3) # =&gt; (3.step(by: -1.5, to: -3))
  e.class                      # =&gt; Enumerator::ArithmeticSequence

&lt;b&gt;Positional Arguments&lt;/b&gt;

With optional positional arguments +limit+ and +step+,
their values (or defaults) determine the step and limit:

  squares = []
  4.step(10, 2) {|i| squares.push(i*i) }    # =&gt; 4
  squares # =&gt; [16, 36, 64, 100]
  squares = []
  4.step(10) {|i| squares.push(i*i) }
  squares # =&gt; [16, 25, 36, 49, 64, 81, 100]
  squares = []
  4.step {|i| squares.push(i*i); break if i &gt; 10 }  # =&gt; nil
  squares # =&gt; [16, 25, 36, 49, 64, 81, 100, 121]</pre>

<p><strong>Implementation Notes</strong></p>

<pre>If all the arguments are integers, the loop operates using an integer
counter.

If any of the arguments are floating point numbers, all are converted
to floats, and the loop is executed
&lt;i&gt;floor(n + n*Float::EPSILON) + 1&lt;/i&gt; times,
where &lt;i&gt;n = (limit - self)/step&lt;/i&gt;.</pre>

                              <div class="method-source-code" id="step-source">
            <pre>static VALUE
num_step(int argc, VALUE *argv, VALUE from)
{
    VALUE to, step;
    int desc, inf;

    if (!rb_block_given_p()) {
        VALUE by = Qundef;

        num_step_extract_args(argc, argv, &amp;to, &amp;step, &amp;by);
        if (!UNDEF_P(by)) {
            step = by;
        }
        if (NIL_P(step)) {
            step = INT2FIX(1);
        }
        else if (rb_equal(step, INT2FIX(0))) {
            rb_raise(rb_eArgError, &quot;step can&#39;t be 0&quot;);
        }
        if ((NIL_P(to) || rb_obj_is_kind_of(to, rb_cNumeric)) &amp;&amp;
            rb_obj_is_kind_of(step, rb_cNumeric)) {
            return rb_arith_seq_new(from, ID2SYM(rb_frame_this_func()), argc, argv,
                                    num_step_size, from, to, step, FALSE);
        }

        return SIZED_ENUMERATOR_KW(from, 2, ((VALUE [2]){to, step}), num_step_size, FALSE);
    }

    desc = num_step_scan_args(argc, argv, &amp;to, &amp;step, TRUE, FALSE);
    if (rb_equal(step, INT2FIX(0))) {
        inf = 1;
    }
    else if (RB_FLOAT_TYPE_P(to)) {
        double f = RFLOAT_VALUE(to);
        inf = isinf(f) &amp;&amp; (signbit(f) ? desc : !desc);
    }
    else inf = 0;

    if (FIXNUM_P(from) &amp;&amp; (inf || FIXNUM_P(to)) &amp;&amp; FIXNUM_P(step)) {
        long i = FIX2LONG(from);
        long diff = FIX2LONG(step);

        if (inf) {
            for (;; i += diff)
                rb_yield(LONG2FIX(i));
        }
        else {
            long end = FIX2LONG(to);

            if (desc) {
                for (; i &gt;= end; i += diff)
                    rb_yield(LONG2FIX(i));
            }
            else {
                for (; i &lt;= end; i += diff)
                    rb_yield(LONG2FIX(i));
            }
        }
    }
    else if (!ruby_float_step(from, to, step, FALSE, FALSE)) {
        VALUE i = from;

        if (inf) {
            for (;; i = rb_funcall(i, &#39;+&#39;, 1, step))
                rb_yield(i);
        }
        else {
            ID cmp = desc ? &#39;&lt;&#39; : &#39;&gt;&#39;;

            for (; !RTEST(rb_funcall(i, cmp, 1, to)); i = rb_funcall(i, &#39;+&#39;, 1, step))
                rb_yield(i);
        }
    }
    return from;
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_c" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_c  &rarr;  complex
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns the value as a complex.</p>

                              <div class="method-source-code" id="to_c-source">
            <pre>static VALUE
numeric_to_c(VALUE self)
{
    return rb_complex_new1(self);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-to_int" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          to_int &rarr; integer
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> as an integer; converts using method <code>to_i</code> in the derived class.</p>

<p>Of the Core and Standard Library classes, only <a href="Rational.html"><code>Rational</code></a> and <a href="Complex.html"><code>Complex</code></a> use this implementation.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-constant">Rational</span>(<span class="ruby-value">1</span>, <span class="ruby-value">2</span>).<span class="ruby-identifier">to_int</span> <span class="ruby-comment"># =&gt; 0</span>
<span class="ruby-constant">Rational</span>(<span class="ruby-value">2</span>, <span class="ruby-value">1</span>).<span class="ruby-identifier">to_int</span> <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">0</span>).<span class="ruby-identifier">to_int</span>  <span class="ruby-comment"># =&gt; 2</span>
<span class="ruby-constant">Complex</span>(<span class="ruby-value">2</span>, <span class="ruby-value">1</span>)         <span class="ruby-comment"># Raises RangeError (non-zero imaginary part)</span>
</pre>

                              <div class="method-source-code" id="to_int-source">
            <pre>static VALUE
num_to_int(VALUE num)
{
    return num_funcall0(num, id_to_i);
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-truncate" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          truncate(digits = 0) &rarr; integer or float
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>self</code> truncated (toward zero) to a precision of <code>digits</code> decimal digits.</p>

<p>Numeric implements this by converting <code>self</code> to a <a href="Float.html"><code>Float</code></a> and invoking <a href="Float.html#method-i-truncate"><code>Float#truncate</code></a>.</p>

                              <div class="method-source-code" id="truncate-source">
            <pre>static VALUE
num_truncate(int argc, VALUE *argv, VALUE num)
{
    return flo_truncate(argc, argv, rb_Float(num));
}</pre>
                              </div>
                            </div>


                          </div>

                  <div id="method-i-zero-3F" class="method-detail ">
                      <div class="method-heading">
                        <span class="method-callseq">
                          zero? &rarr; true or false
                              </span>
                              <span class="method-click-advice">click to toggle source</span>
                            </div>

                            <div class="method-description">
                              <p>Returns <code>true</code> if <code>zero</code> has a zero value, <code>false</code> otherwise.</p>

<p>Of the Core and Standard Library classes, only <a href="Rational.html"><code>Rational</code></a> and <a href="Complex.html"><code>Complex</code></a> use this implementation.</p>

                              <div class="method-source-code" id="zero-3F-source">
            <pre>static VALUE
num_zero_p(VALUE num)
{
    return rb_equal(num, INT2FIX(0));
}</pre>
                              </div>
                            </div>


                          </div>

                          </section>

              </section>
              </main>



            </div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is provided by <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>. </p><p><a href="https://jamesbritt.bandcamp.com/">Hack your world.  Feed your head.  Live curious</a>.</p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

